package pub.wkq.api;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import pub.wkq.api.controller.intercept.JWTCurrentUserInterceptor;
import pub.wkq.api.controller.intercept.SMSIntercept;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    /**
     * 在 springboot 容器中放入拦截器
     *
     * @return SMSIntercept
     */
    @Bean
    public SMSIntercept smsIntercept() {
        return new SMSIntercept();
    }

    @Bean
    public JWTCurrentUserInterceptor jwtCurrentUserInterceptor() {
        return new JWTCurrentUserInterceptor();
    }

    /**
     * 注册拦截器，并且拦截指定的路由
     *
     * @param registry 拦截器注册器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(smsIntercept()).addPathPatterns("/passport/sendCode");
        registry.addInterceptor(jwtCurrentUserInterceptor()).addPathPatterns("/**");
    }
}